home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-08-01 | 3.3 KB | 123 lines |
- /*
- * Exit.java - Provides an exit button
- * eCross is Copyright (C) 2000 Romain Guy
- * guy.romain@bigfoot.com
- * www.jext.org
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
- import waba.fx.*;
-
- /**
- * A control that displays an exit button
- * @version 1.0
- * @author Romain Guy <guy.romain@bigfoot.com>
- */
-
- public class Exit extends Bounded
- {
- private byte state = 0;
- private Image exitImage = new Image("datas/exit.bmp");
-
- /**
- * Creates a new exit button.
- */
-
- public Exit() { }
-
- /**
- * Handles a pen down event.
- * @param parent The caller
- * @param g The <code>Graphics</code> surface of the caller
- * @param x The x coordinate of the event
- * @param y The y coordinate of the event
- * @return <code>true</code> if the event was handled
- */
-
- public boolean handlePenEvent(eCross parent, Graphics g, int x, int y)
- {
- if (state == 0)
- {
- if (x > this.x && x < (this.x + this.width) &&
- y > this.y && y < (this.y + this.height))
- {
- parent.pauseTimer();
-
- g.setColor(255, 255, 255);
- // erase place of the window
- g.fillRect(19, 59, 122, 42);
- /////////////////////////////////////////
- // we should erase grid informations here
-
- g.setColor(0, 0, 0);
- g.drawRect(20, 60, 120, 40);
-
- Font font = new Font("Helvetica", Font.BOLD, 10);
- g.setFont(font);
- FontMetrics fm = parent.getFontMetrics(font);
- String text = new String("Really quit eCross ?");
- g.drawText(text, (160 - fm.getTextWidth(text)) / 2, 65);
-
- g.drawRect(48, 80, 30, 15);
- g.drawDots(50, 95, 78, 95);
- g.drawDots(78, 94, 78, 82);
- text = new String("Yes");
- g.drawText(text, 48 + (30 - fm.getTextWidth(text)) / 2, 82);
-
- g.drawRect(82, 80, 30, 15);
- g.drawDots(84, 95, 112, 95);
- g.drawDots(112, 94, 112, 82);
- text = new String("No");
- g.drawText(text, 82 + (30 - fm.getTextWidth(text)) / 2, 82);
-
- state = 1;
-
- return true;
- }
- } else if (state == 1) {
-
- // click on yes
- if (x > 48 && x < 78 &&
- y > 80 && y < 95)
- {
- parent.exit(0);
- } else if (x > 82 && x < 112 &&
- y > 80 && y < 95)
- {
- state = 0;
- parent.draw();
- parent.resumeTimer();
- }
-
- return true;
- }
-
- return false;
- }
-
- public void paint(Graphics g)
- {
- g.setColor(255, 255, 255);
- g.fillRect(x, y, width, height);
- g.setColor(0, 0, 0);
- g.drawRect(x, y, width, height);
-
- g.drawImage(exitImage, x + 2, y + 2);
- }
- }
-
- // End of Exit.java
-